local yeEnyuan = fk.CreateSkill({
  name = "ye__enyuan",
  tags = { Skill.Compulsory },
})

Fk:loadTranslationTable{
  ["ye__enyuan"] = "恩怨",
  [":ye__enyuan"] = "锁定技，准备阶段，你移除所有“眩”标记，移除“眩”标记的角色失去1点体力，然后你回复1点体力。",
}

yeEnyuan:addEffect(fk.EventPhaseStart, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return
      player:hasSkill(yeEnyuan.name) and
      target == player and
      player.phase == Player.Start and
      table.find(player.room:getOtherPlayers(player, false), function(p) return p:getMark("@@ye__xuanhuo") > 0 end)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name)
    for _, p in ipairs(room:getOtherPlayers(player)) do
      if p:getMark("@@ye__xuanhuo") > 0 then
        room:setPlayerMark(p, "@@ye__xuanhuo", 0)
        local mark = player:getTableMark("ye__xuanhuo_count")
        local count = mark[tostring(p.id)] or 0
        if count >= 99 then
          player:broadcastSkillInvoke(self.name, 1)
          if not player:isNude() then
            local cards = #player:getCardIds("he") < 0 and player:getCardIds("he") or
            room:obtainCard(p, cards, false, fk.ReasonGive)
          end
        else
          player:broadcastSkillInvoke(self.name, 2)
          room:loseHp(p, 1, self.name)
          if not player.dead and player:isWounded() then
            room:recover { num = 1, skillName = self.name, who = player , recoverBy = player}
          end
        end
      end
    end
    room:setPlayerMark(player, "ye__xuanhuo_count", 0)
  end,
})

return yeEnyuan
